-- UISkyCityPetInfo
-- Create by chendh
-- 天空之城冈布奥/机器人信息界面

require "game/ui/form/sky_city/UIAirShipSkillDesc"

-- UISkyCityPetInfo继承自Layer
UISkyCityPetInfo = class("UISkyCityPetInfo", function()
    return cc.Layer:create();
end);

function UISkyCityPetInfo.create(classId, campId, targetType, groupIndex, type)
    return UISkyCityPetInfo.new(classId, campId, targetType, groupIndex, type);
end

-- 内部函数声明
local sortSkills;

-- 构造函数
function UISkyCityPetInfo:ctor(classId, campId, targetType, groupIndex, type)
    -- 初始化
    self:setName("UISkyCityPetInfo");
    local node = cc.CSLoader:createNode("layout/sky_city/SkyCityPetInfo.csb");
    self:addChild(node);
    self.node = node;
    self.classId = classId;
    self.campId = campId;
    self.targetType = targetType;
    self.groupIndex = groupIndex or 0;
    self.type = type;

    local CT = node:getChildByName("CT");
    self.scrollView = CT:getChildByName("scroll_view");

    -- 容器原本的内高
    self.oriHeight = self.scrollView:getInnerContainerSize().height

    -- 注册事件处理回调函数
    self:registerEventCallback();

    -- 注册点击事件
    self:registerTouchEvent();

    -- 重绘
    self:redraw();

    -- 绘制装备属性、秘宝
    self:redrawPetAddon();

    -- 适配
    self:resize();
end

-- 适配
function UISkyCityPetInfo:resize()
    local node = self.node;

    -- bg居中显示并充满整个屏幕
    AlignM.fitToScreen(node, "bg");

    -- CT居中并缩放至合适大小
    AlignM.alignToCenter(node, "CT");

    -- BT置于底部并缩放至合适大小
    AlignM.alignToBottomCenter(node, "BT");
end

-- 重绘界面
function UISkyCityPetInfo:redraw()
    -- 标题
    local titleLabel = findChildByName(self.node, "CT/template/title_label");
    -- 星级
    local starNode = findChildByName(self.node, "CT/template/star_node");
    -- 图标或者模型
    local petImg   = findChildByName(self.node, "CT/pet_icon");
    local modelNode = findChildByName(self.node, "CT/pet_model");
    -- 战力信息
    local starName = findChildByName(self.node, "CT/attrib_star/name");
    local starValue = findChildByName(self.node, "CT/attrib_star/value");
    local feedName = findChildByName(self.node, "CT/attrib_feed/name");
    local feedValue = findChildByName(self.node, "CT/attrib_feed/value");
    local equipName = findChildByName(self.node, "CT/attrib_equip/name");
    local equipValue = findChildByName(self.node, "CT/attrib_equip/value");
    local abilityName = findChildByName(self.node, "CT/attrib_army_ability/name");
    local abilityValue = findChildByName(self.node, "CT/attrib_army_ability/value");

    TextStyleM.setTextStyle(starName, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, -1);
    TextStyleM.setTextStyle(starValue, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, -1);
    TextStyleM.setTextStyle(feedName, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, -1);
    TextStyleM.setTextStyle(feedValue, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, -1);
    TextStyleM.setTextStyle(equipName, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, -1);
    TextStyleM.setTextStyle(equipValue, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, -1);
    TextStyleM.setTextStyle(abilityName, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, -1)
    TextStyleM.setTextStyle(abilityValue, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, -1);

    starName:setString(getLocStr("sky_city_pet_star"));
    feedName:setString(getLocStr("sky_city_pet_feed"));
    equipName:setString(getLocStr("sky_city_pet_equip"));
    abilityName:setString(getLocStr("sky_city_pet_ability"));

    if self.targetType == "pet" then
        local pet  = ME.user.pets[self.classId];
        local rank = pet.rank;

        -- 显示标题
        titleLabel:setString(PetM.query(self.classId, "name"));
        TextStyleM.setArtWordTitleStyle(titleLabel);

        local starPath = "images/ui/symbol/star_large.png";

        -- 如果冈布奥已觉醒，使用橙色的星星
        if AwakeM.isCarved(self.classId) then
            starPath = "images/ui/symbol/star_large3.png";
        end

        -- 星级
        local tStar = createStarLayer(rank, starPath, "center");
        if tStar then
            starNode:removeAllChildren();
            starNode:addChild(tStar);
        end

        -- 冈布奥模型
        local iconPath = getHeroIconPath(pet:getIcon());
        modelNode:removeAllChildren();
        local modelId = pet:getModelId();
        local petInfo = PetM.queryModel(modelId);
        self.heroModel = createHeroModel(modelId, petImg, modelNode, petInfo["model_scale"], iconPath);

        self.heroModel:setScale(self.heroModel:getScale() * 1.3);

        -- 计算战力数据
        local petAbility, abilityInfo = FormulaM.invoke("CALC_SINGLE_PET_ABILITY", pet)
        starValue:setString("+" .. changeNumString(abilityInfo["rank"]));
        feedValue:setString("+" .. changeNumString(abilityInfo["feed"]));
        equipValue:setString("+" .. changeNumString(abilityInfo["equip"]));
        abilityValue:setString("+" .. changeNumString(petAbility));
    else
        -- 显示标题
        titleLabel:setString(SkyRobotM.query(self.classId, "name"));
        TextStyleM.setArtWordTitleStyle(titleLabel);

        -- 星级
        local rank = SkyRobotM.query(self.classId, "rank")
        local tStar = createStarLayer(rank,"images/ui/symbol/star_large.png", "center");
        if tStar then
            starNode:removeAllChildren();
            starNode:addChild(tStar);
        end

        -- 机器人图片
        local iconPath = getRobotIconPath(SkyRobotM.query(self.classId, "icon"));
        modelNode:removeAllChildren();
        modelNode:setVisible(false);
        petImg:loadTexture(iconPath);
        petImg:setScale(1.5);

        -- 计算战力数据
        local fight_ability = SkyRobotM.query(self.classId, "fight_ability");
        starValue:setString("+" .. fight_ability);
        feedValue:setString("+0");
        equipValue:setString("+0");
        abilityValue:setString(fight_ability);
    end

    -- 更换、下阵 按钮是否显示
    local btnChange = findChildByName(self.node, "BT/btn_change");
    local btnUnload = findChildByName(self.node, "BT/btn_unload");

    local isInTeam = false;
    local skyGroup = ME.user.dbase:query("skyArmyGroup", {});
    local group = skyGroup[self.campId] or {};

    if self.type == "replace" then
        btnChange:setVisible(false);
        btnUnload:setVisible(true);
    else
        btnChange:setVisible(true);
        btnUnload:setVisible(false);
    end
end

-- 注册事件处理回调函数
function UISkyCityPetInfo:registerEventCallback()
    -- 界面析构后，需要清理下
    self:registerScriptHandler(function(eventType)
        if eventType == "exit" then
            EventMgr.removeAll("UISkyCityPetInfo");
        elseif eventType == "enter" then

        end
    end);

    -- 注册获得焦点的回调
    EventMgr.register("UISkyCityPetInfo", event.FOCUS_CHANGED, function(para)
        if para["get"] == "UISkyCityPetInfo" then
            local btNode = findChildByName(self.node, "BT");
            btNode:setVisible(true);
        elseif para["lose"] == "UISkyCityPetInfo" then
            local btNode = findChildByName(self.node, "BT");
            btNode:setVisible(false);
        end
    end);

end

-- 注册点击事件
function UISkyCityPetInfo:registerTouchEvent()
    -- 注册返回按钮点击事件
    local btnBack = findChildByName(self.node, "BT/btn_back");
    local function onBackClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            -- 关闭当前界面
            AudioM.playFx("ship_return");
            UIMgr.getCurrentScene():removeFormByName("UISkyCityPetInfo");
        end
    end
    AddBackEventHandler(self, btnBack, onBackClick);
    TextStyleM.setTextStyle(btnBack, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btnBack:setTitleText(getLocStr("btn_text_back"));

    -- 注册 更换 按钮点击事件
    local btnChange = findChildByName(self.node, "BT/btn_change");
    local function onChangeClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            if self.type == "replace" then
                -- 打开更换界面
                require "game/ui/form/sky_city/UISkyCityPetList"

                -- 打开冈布奥列表界面
                local uiForm = UISkyCityPetList.create(self.campId, self.classId, self.groupIndex);
                UIMgr.getCurrentScene():addForm(uiForm);
            else
                -- 上阵

                -- 先尝试将更换的下阵了
                local uiTeam = UIMgr.getCurrentScene():getFormByName("UISkyCityTeam");
                local petList = uiTeam:getGroupPetList();
                local robotList = uiTeam:getGroupRobotList();
                local unload;
                local unloadType;

                if self.groupIndex > 0 and self.groupIndex <= #petList then
                    -- 冈布奥下阵
                    unload = petList[self.groupIndex];
                    unloadType = "pet";
                elseif self.groupIndex > #petList and self.groupIndex <= #petList + #robotList then
                    -- 机器人下阵
                    unload = robotList[self.groupIndex - #petList];
                    unloadType = "robot";
                end

                -- 保存阵容
                SkyCombatM.saveGroup(self.campId, self.classId, self.targetType, unload, unloadType);
                UIMgr.getCurrentScene():removeFormByName("UISkyCityPetList");
            end

            AudioM.playFx("ship_click");
            UIMgr.getCurrentScene():removeFormByName("UISkyCityPetInfo");
        end
    end
    btnChange:addTouchEventListener(onChangeClick);
    TextStyleM.setTextStyle(btnChange, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    if self.type == "replace" then
        btnChange:setTitleText(getLocStr("btn_text_change"));
    else
        btnChange:setTitleText(getLocStr("btn_text_actived"));
    end

    -- 注册 下阵 按钮点击事件
    local btnUnload = findChildByName(self.node, "BT/btn_unload");
    local function onUnloadClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            local campId = self.campId;
            local petList = SkyCombatM.getGroup(campId);
            local robotMap = SkyRobotM.getRobotsByCamp(campId);
            local robotNum = 0;
            for _, num in pairs(robotMap) do
                robotNum = robotNum + num;
            end

            if robotNum + #petList <= 1 then
                alert(getLocStr("keep_last_one"));
                return;
            end

            -- 下阵
            SkyCombatM.saveGroup(self.campId, nil, nil, self.classId, self.targetType);

            AudioM.playFx("ship_click");
            UIMgr.getCurrentScene():removeFormByName("UISkyCityPetInfo");
            UIMgr.getCurrentScene():removeFormByName("UISkyCityPetList");
        end
    end
    btnUnload:addTouchEventListener(onUnloadClick);
    TextStyleM.setTextStyle(btnUnload, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btnUnload:setTitleText(getLocStr("btn_text_unload_group"));
end

-- 打开秘宝详细信息页
function UISkyCityPetInfo:airShipSkillDesc(node, skillId)
    local function onClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            if UIMgr.getCurrentScene():getFormByName("UIAirShipSkillDesc") then
                return;
            end
            local uiAirShipSkillDesc = UIAirShipSkillDesc.create(skillId);
            UIMgr.getCurrentScene():addForm(uiAirShipSkillDesc);
            AudioM.playFx("ui_open1");
        end
    end
    node:addTouchEventListener(onClick);
end

-- 绘制宠物的秘宝信息、装备属性
function UISkyCityPetInfo:redrawPetAddon()
    local totalScrollHeight = 15;
    local childList = {};
    local wordCountPerLine = 20;
    if not isChineseLang() then
        wordCountPerLine = nil;
    end

    -- 去除所有的子节点
    self.scrollView:removeAllChildren();

    -- 初始化秘宝和装备信息
    local infos = {};

    if self.targetType == "pet" then
        infos = self:initSkillAndEquip();
    elseif self.targetType == "robot" then
        local robotConfig = SkyRobotM.query(self.classId);
        local robotInfo = SkyRobotM.getRobotInfo(self.classId);
        infos = {{
            ["name"] = robotConfig["name"],
            ["desc"] = robotConfig["desc"],
            ["propDesc"] = robotConfig["prop_desc"],
            ["fighting_num"] = robotInfo["fighting"],
            ["free_num"] = robotInfo["total"] - robotInfo["fighting"],
        }};
    end

    local contentKerning, kerning = 0, 0;
    if not isChineseLang() then
        contentKerning, kerning = -1, -1;
    end

    local petItem = cc.CSLoader:createNode("layout/sky_city/SmallPetNode.csb");
    -- 循环复用
    local widget = replaceNodeWithWidget(petItem);

    for i = 1, #infos do
        -- 装备
        local info = infos[i];
        local child = cc.CSLoader:createNode("layout/comment/CommentItem.csb");
        local bgImg = child:getChildByName("bg");
        local numLabel = child:getChildByName("num");
        local contentLabel = ccui.Text:create();
        local dateLabel = child:getChildByName("date");
        local praiseImg = child:getChildByName("praise");
        local nameLabel = child:getChildByName("name");

        -- 隐藏掉不必要的
        numLabel:setVisible(false);
        dateLabel:setVisible(false);
        praiseImg:setVisible(false);

        contentLabel:setAnchorPoint(0, 1);
        contentLabel:setPosition(cc.p(child:getChildByName("content"):getPosition()));
        TextStyleM.setTextStyle(contentLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, nil, contentKerning, nil, nil, wordCountPerLine);
        child:addChild(contentLabel);

        nameLabel:setPosition(cc.p(nameLabel:getPositionX() - 4, nameLabel:getPositionY() - 3));
        contentLabel:setPositionX(contentLabel:getPositionX() - 4);

        if self.targetType == "pet" then
            if info["isEquip"] then
                -- 装备信息
                local classId = info["classId"];
                local name = ItemM.query(classId, "name");
                TextStyleM.setTextStyle(nameLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, kerning);
                nameLabel:setString(name);

                contentLabel:setString(extractString(info.propDesc));

                local petNode = widget:clone();
                local petImg = petNode:getChildByName("icon");

                local icon = PetM.getDefaultIcon(self.classId);
                petImg:loadTexture(getSmallHeroIconPath(icon));

                -- 计算位置
                child:addChild(petNode);
                local posY = nameLabel:getPositionY();
                local posX = self.scrollView:getInnerContainerSize().width / 2 - 34;
                petNode:setPosition(cc.p(posX, posY));
                petNode:setScale(0.8);

                -- 装备要换个背景图片
                bgImg:loadTexture(getTitleBgIconPath("point_red"));
            elseif info["isCarving"] then
                -- 冈布奥雕像信息
                local name = info["name"];
                TextStyleM.setTextStyle(nameLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, kerning);
                nameLabel:setString(name);

                contentLabel:setString(extractString(info.propDesc));

                local petNode = widget:clone();
                local petImg = petNode:getChildByName("icon");

                local icon = PetM.getDefaultIcon(self.classId);
                petImg:loadTexture(getSmallHeroIconPath(icon));

                -- 计算位置
                child:addChild(petNode);
                local posY = nameLabel:getPositionY();
                local posX = self.scrollView:getInnerContainerSize().width / 2 - 34;
                petNode:setPosition(cc.p(posX, posY));
                petNode:setScale(0.8);

                -- 装备要换个背景图片
                bgImg:loadTexture(getTitleBgIconPath("point_red"));
            else
                -- 秘宝信息
                TextStyleM.setTextStyle(nameLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, kerning);
                nameLabel:setString(info.name);
                contentLabel:setString(SkyShipSkillM.getShipSkillDetail(info.id));

                -- 置灰颜色
                local blendColor = TextStyleM.TEXT_COLOR_BLEND;

                local needCount = #info.group;
                local hasCount = 0;

                -- 冈布奥图标
                for index, id in pairs(info.group) do
                    local petItem = widget:clone();
                    local iconImg = petItem:getChildByName("icon");
                    local icon = PetM.getDefaultIcon(id);
                    iconImg:loadTexture(getSmallHeroIconPath(icon));

                    -- 计算位置
                    child:addChild(petItem);
                    local posY = nameLabel:getPositionY();
                    local posX = self.scrollView:getInnerContainerSize().width / 2 - index * 38 + 4;
                    petItem:setPosition(cc.p(posX, posY));
                    petItem:setScale(0.8);

                    if not SkyCombatM.isInGroup(id, self.campId) then
                        -- 没出战，置灰
                        setGrayTransMode(iconImg, true);
                    end

                    -- 注册点击打开详细信息
                    local petBg = petItem:getChildByName("bg");
                    petBg:setTouchEnabled(true);

                    self:airShipSkillDesc(petBg, info.id);
                end

                -- 装备要换个背景图片
                bgImg:loadTexture(getTitleBgIconPath("point_yellow"));
            end

            -- 置灰颜色
            local blendColor = TextStyleM.TEXT_COLOR_BLEND;

            -- 秘宝没激活或者装备没获得
            if info["isEquip"] == 0 or info["activity"] == 0 or info["hasOwn"] == 0 then
                TextStyleM.setTextStyle(nameLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, kerning);
                TextStyleM.setTextStyle(contentLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, nil, contentKerning, nil, nil, wordCountPerLine);
                if info["isEquip"] then
                    local classId = info["classId"];
                    local name = ItemM.query(classId, "name");
                    nameLabel = applyString(nameLabel, name .. "[brown]" .. getLocStr("unequip") .. "[-]");
                elseif info["hasOwn"] == 0 then
                    nameLabel = applyString(nameLabel, info.name .. "[brown]" .. getLocStr("not_captured") .. "[-]");
                else
                    nameLabel = applyString(nameLabel, info.name .. "[brown]" .. getLocStr("not_be_active2") .. "[-]");
                end
            end
        else
            -- 机器人
            TextStyleM.setTextStyle(nameLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false);
            nameLabel:setString(info["name"]);

            bgImg:loadTexture(getTitleBgIconPath("point_yellow"));

            local desc = info["desc"];
            desc = desc .. "\n\n[brown]" .. info["propDesc"] .. "[-]";
            desc = desc .. "\n[brown]" .. string.format(getLocStr("robot_num_desc"), info["fighting_num"], info["free_num"]) .. "[-]";

            TextStyleM.setTextStyle(contentLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, nil, contentKerning, nil, nil, wordCountPerLine);

            contentLabel = applyString(contentLabel, desc);
        end

        -- 设置背景高度
        local finalHight = getRealContentSize(contentLabel).height + 65;
        bgImg:setContentSize(bgImg:getContentSize().width, finalHight);

        -- 计算容器最终内高
        totalScrollHeight = totalScrollHeight + finalHight + 15;

        child.bgHeight = finalHight;

        table.insert(childList, child);
    end

    -- 设置容器内高
    self.scrollView:setInnerContainerSize(cc.size(self.scrollView:getInnerContainerSize().width,
       math.max(totalScrollHeight, self.oriHeight)));

    -- 统一布局
    local leftHeight = math.max(totalScrollHeight, self.oriHeight);
    for i = 1, #childList do
        local child = childList[i];
        local posY = leftHeight - 110;
        local posX = self.scrollView:getInnerContainerSize().width / 2;
        child:setPosition(cc.p(posX, posY));
        leftHeight = leftHeight - child.bgHeight - 10;
        self.scrollView:addChild(child);
    end
end

-- 获取宠物支持秘宝并进行排序
function UISkyCityPetInfo:sortSkillsInfo()
    local infos = SkyShipSkillM.getAllShipSkillsByPetId(self.classId);

    for i = 1, #infos do
        local info = infos[i];
        local hasCount = 0;

        if SkyShipSkillM.hasOwn(info.id) then
            info["hasOwn"] = 1;
        else
            info["hasOwn"] = 0;
        end

        for index, id in pairs(info.group) do
            if SkyCombatM.isInGroup(id, self.campId) then
                hasCount = hasCount + 1;
            end

            if hasCount >= #info.group and info["hasOwn"] == 1 then
                info["activity"] = 1;
            else
                info["activity"] = 0;
            end

            info["activeAmount"] = hasCount;
        end


    end

    table.sort(infos, sortSkills);
    return infos;
end

-- 对冈布奥进行排序  按（已激活>有上阵>没上阵）/ ID排序顺序
function sortSkills(item1, item2)
    if item1.hasOwn ~= item2.hasOwn then
        -- 获得的大于没获得的
        return item1.hasOwn > item2.hasOwn;
    elseif item1.activity ~= item2.activity then
        -- 激活的大于没激活的
        return item1.activity > item2.activity;
    elseif item1.activeAmount ~= item2.activeAmount then
        -- 有上阵大于没上阵
        if (item1.activeAmount * item2.activeAmount) == 0 then
            return item1.activeAmount > item2.activeAmount;
        end
    end
    -- 按ID从小到大
    return item1.id < item2.id;
end

-- 排序冈布奥装备属性加成
function UISkyCityPetInfo:sortEquipmentsProp()
    local pet = PetM.getMyPet(self.classId);
    local equipments = PetM.calcUpgradeRankNeed(self.classId, 5);
    local ret = {};
    local attribs = {"fire", "armor", "speed", "luck"};
    local equips = { EquipM.getHeroEquip(pet, EQUIP_TYPE_MEDAL, 1), EquipM.getHeroEquip(pet, EQUIP_TYPE_WEAPON, 1), };
    local desc;

    for index, arr in pairs(equipments) do
        local classId = arr[2];

        local props = EquipM.calcBaseProp(ME.user, classId);
        local propDesc = "";
        local isEquip = 0;

        for _, prop in pairs(props) do
            if table.indexOf(attribs, prop[2]) > 0 then
                if #propDesc > 0 then
                    propDesc = propDesc .. getLocStr("pause_mark");
                end

                desc = PropM.getPropDesc(prop);
                -- 此处只显示纯属性
                if string.startWith(desc, getLocStr("when_sky_combat")) then
                    desc = string.sub(desc, 1 + string.len(getLocStr("when_sky_combat")), -1);
                end

                propDesc = propDesc .. desc;
            end
        end

        if table.indexOf(equips, classId) > 0 then
            isEquip = 1;
        end

        if #propDesc > 0 then
            table.insert(ret, {["classId"] = classId, ["propDesc"] = propDesc, ["isEquip"] = isEquip, });
        end
    end

    return ret;
end

-- 冈布奥的觉醒雕像属性
function UISkyCityPetInfo:getAwakeInfo()
    local ret = {};
    if not AwakeM.isCarved(self.classId) then
        return ret;
    end

    local pet = PetM.getMyPet(self.classId);
    local props = AwakeM.fetchAwakeCarvingProps(pet);
    local attribs = {"fire", "armor", "speed", "luck"};
    local propDesc = "";

    for _, prop in pairs(props) do
        if table.indexOf(attribs, prop[2]) > 0 then
            if #propDesc > 0 then
                propDesc = propDesc .. getLocStr("pause_mark");
            end

            desc = PropM.getPropDesc(prop);
            -- 此处只显示纯属性
            if string.startWith(desc, getLocStr("when_sky_combat")) then
                desc = string.sub(desc, 1 + string.len(getLocStr("when_sky_combat")), -1);
            end

            propDesc = propDesc .. desc;
        end
    end

    if #propDesc > 0 then
        local name = string.format(getLocStr("awake_carving_tip_title"), PetM.query(self.classId, "short_name"));
        ret = {["name"] = name, ["propDesc"] = propDesc, ["isCarving"] = 1, };
    end

    return ret;
end

-- 初始化秘宝和装备属性列表
function UISkyCityPetInfo:initSkillAndEquip()
    local totalList = {};
    local equipList = self:sortEquipmentsProp();
    local skillList = self:sortSkillsInfo();
    local awakeInfo = self:getAwakeInfo();

    -- 排序规则：已激活秘宝、已激活装备、已激活雕像、未激活秘宝、未激活装备
    local pet = PetM.getMyPet(self.classId);
    local skillIndex = 1;

    for index = skillIndex, #skillList do
        local info = skillList[index];

        if info["activity"] == 1 then
            -- 已激活的秘宝
            skillIndex = skillIndex + 1;

            table.insert(totalList, info);
        end
    end

    for index = 1, #equipList do
        local info = equipList[index];

        if info["isEquip"] == 1 then
            -- 已穿着的装备
            table.insert(totalList, info);
        end
    end

    -- 雕像属性
    if sizeof(awakeInfo) > 0 then
        table.insert(totalList, awakeInfo);
    end

    for index = skillIndex, #skillList do
        -- 未激活的秘宝
        local info = skillList[index];
        table.insert(totalList, info);
    end

    for index = 1, #equipList do
        -- 未穿着的装备
        local info = equipList[index];
        if info["isEquip"] == 0 then
            -- 已穿着的装备
            table.insert(totalList, info);
        end
    end

    return totalList;
end